<template>
  <div class="app-container">

    <el-row :gutter="20" class="header">
      <el-col :span="7">
        <el-input placeholder="请输入微信昵称或者openid..." v-model="queryForm.query" clearable ></el-input>
      </el-col>
      <el-button type="primary" :icon="Search" @click="initUserList">搜索</el-button>

    </el-row>

    <el-table :data="tableData" stripe style="width: 100%" >
      <el-table-column type="index" label="序号" align="center" width="150" />
      <el-table-column prop="openid" label="openid" />
        <el-table-column prop="avatar" label="头像" width="100" align="center">
          <template v-slot="scope">
            <img :src="getServerUrl()+'image/weixinAvatar/'+scope.row.avatarUrl" width="50" height="50"/>
          </template>
        </el-table-column>
        <el-table-column prop="nickName" label="用户昵称"  width="200" align="center"/>
        <el-table-column prop="status" label="状态？" width="200" align="center" >
          <template v-slot="{row}" >
            <el-switch  v-model="row.status" active-text="正常" @change="statusChangeHandle(row)"
                        inactive-text="禁用" active-value="0" inactive-value="1"></el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="registerDate" label="注册时间" width="200" align="center"/>
        <el-table-column prop="lastLoginDate" label="最后登录时间" width="200" align="center"/>
    </el-table>
    <el-pagination
        v-model:currentPage="queryForm.pageNum"
        v-model:page-size="queryForm.pageSize"
        :page-sizes="[10, 20, 30, 40]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
    />
  </div>

</template>

<script setup>
import {ref} from 'vue';
import requestUtil,{getServerUrl} from "@/util/request";
import { Search ,Delete,DocumentAdd ,Edit, Tools, RefreshRight} from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'


const tableData=ref({})

const total=ref(0)

const queryForm=ref({
  query:'',
  pageNum:1,
  pageSize:10
})

const id=ref(-1)


const initUserList=async()=>{
  const res=await requestUtil.post("business/wxUser/list",queryForm.value);
  tableData.value=res.data.wxUserInfoList;
  total.value=res.data.total;
}

initUserList();

const handleSizeChange=(pageSize)=>{
  queryForm.value.pageNum=1;
  queryForm.value.pageSize=pageSize;
  initUserList();
}

const handleCurrentChange=(pageNum)=>{
  queryForm.value.pageNum=pageNum;
  initUserList();
}


const statusChangeHandle=async (row)=>{
  let res=await requestUtil.get("business/wxUser/updateStatus/"+row.id+"/status/"+row.status);
  if(res.data.code==200){
    ElMessage({
      type: 'success',
      message: '执行成功!'
    })
  }else{
    ElMessage({
      type: 'error',
      message: res.data.msg,
    })
    initUserList();
  }
}

</script>

<style lang="scss" scoped>

.header{
  padding-bottom: 16px;
  box-sizing: border-box;
}

.el-pagination{
  float: right;
  padding: 20px;
  box-sizing: border-box;
}

::v-deep th.el-table__cell{
  word-break: break-word;
  background-color: #f8f8f9 !important;
  color: #515a6e;
  height: 40px;
  font-size: 13px;

}

.el-tag--small {
  margin-left: 5px;
}
</style>
